package o;

import android.content.Context;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStreamReader;
import org.json.JSONObject;

public class che {
    private static che ˋ;
    private static final Object ॱ = new Object();

    public static che ˎ() {
        che o_che;
        synchronized (ॱ) {
            if (ˋ == null) {
                ˋ = new che();
            }
            o_che = ˋ;
        }
        return o_che;
    }

    public cia ˎ(Context context, int i) {
        cia o_cia = new cia(context);
        ˊ(context, o_cia, i);
        return o_cia;
    }

    public void ˊ(Context context, cia o_cia, int i) {
        if (o_cia == null) {
            Logger.e("LocalCardManager", "CardDataProvider cannot be null");
            return;
        }
        o_cia.ॱॱ();
        BaseDetailResponse baseDetailResponse = new BaseDetailResponse();
        try {
            baseDetailResponse.fromJson(new JSONObject(ˊ(context, i)));
            ˏ().ॱ(o_cia, new chd(), baseDetailResponse, true);
        } catch (Exception e) {
            Logger.e("LocalCardManager", "getCardDataProvider error!");
        }
    }

    protected chi ˏ() {
        return new chg();
    }

    private String ˊ(Context context, int i) {
        Closeable openRawResource;
        Closeable bufferedReader;
        Throwable th;
        Throwable th2;
        Closeable closeable = null;
        StringBuilder stringBuilder = new StringBuilder(256);
        try {
            openRawResource = context.getResources().openRawResource(i);
            try {
                bufferedReader = new BufferedReader(new InputStreamReader(openRawResource, "UTF-8"));
                while (true) {
                    try {
                        String readLine = bufferedReader.readLine();
                        if (readLine == null) {
                            break;
                        }
                        stringBuilder.append(readLine);
                    } catch (IOException e) {
                        closeable = bufferedReader;
                    } catch (Throwable th3) {
                        th = th3;
                        closeable = openRawResource;
                        th2 = th;
                    }
                }
                dnw.ˎ(openRawResource);
                dnw.ˎ(bufferedReader);
            } catch (IOException e2) {
                try {
                    Logger.e("LocalCardManager", "loadJSON error!");
                    dnw.ˎ(openRawResource);
                    dnw.ˎ(closeable);
                    return stringBuilder.toString();
                } catch (Throwable th4) {
                    th = th4;
                    bufferedReader = closeable;
                    closeable = openRawResource;
                    th2 = th;
                    dnw.ˎ(closeable);
                    dnw.ˎ(bufferedReader);
                    throw th2;
                }
            } catch (Throwable th42) {
                th = th42;
                bufferedReader = null;
                closeable = openRawResource;
                th2 = th;
                dnw.ˎ(closeable);
                dnw.ˎ(bufferedReader);
                throw th2;
            }
        } catch (IOException e3) {
            openRawResource = null;
            Logger.e("LocalCardManager", "loadJSON error!");
            dnw.ˎ(openRawResource);
            dnw.ˎ(closeable);
            return stringBuilder.toString();
        } catch (Throwable th5) {
            th2 = th5;
            bufferedReader = null;
            dnw.ˎ(closeable);
            dnw.ˎ(bufferedReader);
            throw th2;
        }
        return stringBuilder.toString();
    }
}
